package config

import (
	"github.com/micro/go-micro/debug/log"
	"gopkg.in/ini.v1"
)

//服务端配置
type ServiceConfig struct {
	ServiceName  string   `ini:"service_name"`
	Port         string   `ini:"port"`
	ZipkinAddr   string   `ini:"zipkin_addr"`
	RegistryAddr string   `ini:"registry_addr"`
	StaticPath   string   `ini:"static_path"`
	Mode         string   `ini:"mode"`
	Version      string   `ini:"version"`
}

var config = new(ServiceConfig)
func GetConfig() *ServiceConfig {
	return config
}

func InitConfig(path string) *ServiceConfig {
	cfg, err := ini.Load(path)
	if err != nil {
		log.Fatal("InitConfig: ", path, ".  config err: ", err.Error())
	}
	err = cfg.MapTo(config)
	if err != nil {
		log.Fatal("InitConfig: ", path, ".  MapTo err: ", err.Error())
	}
	return config
}